﻿

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<新建预存帐号>
-- =============================================

CREATE PROCEDURE [dbo].[proc_AB_Interface_Create2](
	@CompanyId INT,
	@CompanName NVARCHAR(50),
	@syzh INT --接口帐号的ID
)
AS
DECLARE @productId VARCHAR(200)
DECLARE @ProductName NVARCHAR(50)
DECLARE @Count INT
BEGIN
SELECT @productId=ProductId,@ProductName=Productname+'(预存)' -- 得到产品ID和产品名称
      FROM AB_Interface WHERE id=@syzh

SELECT @Count=COUNT(*) FROM AB_Interface 
    WHERE CompanyId=@CompanyId AND syzh=@syzh

IF @Count=0  -- @Count=0的时候表示没有重复记录
BEGIN
	INSERT INTO [AB_Interface]
	   ([CompanyId]
	   ,[Companyname]
	   ,[ProductId]
	   ,[Productname]
	   ,[syzh])
	VALUES
	   (
		@CompanyId
		,@CompanName
		,@productId
		,@ProductName
		,@syzh
	   )
END
ELSE
	BEGIN
		SELECT -1
	END

	SET NOCOUNT ON;
END